package cn.bingoogolapple.bgabanner.transformer;

import ohos.agp.components.Component;

/**
 * 作者:王浩 邮件:bingoogolapple@gmail.com
 * 创建时间:15/6/19 17:39
 * 描述:
 */
public class CubePageTransformer extends BGAPageTransformer {
    private float mMaxRotation = 90.0f;

    /**
     * constructor
     */
    public CubePageTransformer() {
    }

    /**
     * constructor
     *
     * @param maxRotation
     */
    public CubePageTransformer(float maxRotation) {
        setMaxRotation(maxRotation);
    }

    @Override
    public void handleInvisiblePage(Component view, float position) {
        view.setPivotX(view.getWidth());
        view.setPivotY(view.getWidth() * 0.5f);
        view.setRotationSensitivity(0);
    }

    @Override
    public void handleLeftPage(Component view, float position) {
        view.setPivotX(view.getWidth());
        view.setPivotY(view.getWidth() * 0.5f);
        view.setRotationSensitivity(mMaxRotation * position);
    }

    @Override
    public void handleRightPage(Component view, float position) {
        view.setPivotX(0);
        view.setPivotY(view.getWidth() * 0.5f);
        view.setRotationSensitivity(mMaxRotation * position);
    }

    /**
     * setMaxRotation
     *
     * @param maxRotation
     */
    public void setMaxRotation(float maxRotation) {
        if (maxRotation >= 0.0f && maxRotation <= 90.0f) {
            mMaxRotation = maxRotation;
        }
    }
}
